## Function 
#MinMax <- function(inpath, outpath, para, fun = c("min", "max")) {
MinMax <- function(inpath, outpath, para, fun) {
  output <- sapply(seq(inpath), function(i) {
    print(i)
    df <- read.table(inpath[i], header = T, sep = ",", stringsAsFactors = F, fill=TRUE)
    #out <- switch(fun,
    #              "min" = min(df[para], na.rm = T),
    #              "max" = max(df[para], na.rm = T))
      out <- sapply(seq(fun), function(j) {
              print(j)
              switch(fun[j],
              "min" = min(df[para], na.rm = T),
              "max" = max(df[para], na.rm = T))
      }
      
   )
   print(out)
  }
          )
  write.table(output, outpath)
}


MinMax2 <- function(inpath, outpath, para, fun = c("min", "max")) {
  output <- sapply(seq(inpath), function(i) {
    df <- read.table(inpath[i], header = T, sep = ",", stringsAsFactors = F, fill=TRUE)
    out <- switch(fun,
                  "min" = min(df[para], na.rm = T),
                  "max" = max(df[para], na.rm = T))
    t <- "Hallo"   
    return(out)
   }
          )
  write.table(output, outpath)
}
